<template>
    <div style="height:100%;width:100%;position:relative;">
        <rm-layout-top splitcolor="white" :splitwidth=0 :fixsize="1" :canDrag="false" :key="pagekey" ref="layoutdiv">
            <template v-slot:fix>
                <div class="myclass" :style="{height: '0px' }" ref="topdiv" style="border: 1px solid #ccc" :key="pagekey">
                    <div style="height:100%">
                        <div style="height:calc(100%-30px)">
                            <table style="font-size:12px;white-space: nowrap;" border="0">
                                <tr v-for="(itemlist,index) in CondDatas" :key="index">
                                    <td v-for="(item,sindex) in itemlist" :key="sindex" :colspan="item.valuetype == '9'?'3':'1'">
                                        <table>
                                            <tr>
                                                <td style="width:60px" align="right"> {{item.colname}}</td>
                                                <td :style="{ width: item.valuetype == '9' ?'270px': '135px' }">
                                                    <div v-if="item.valuetype=='0'">
                                                        <!--标识时间选择框--->
                                                        <div v-if="item.dateformat=='1'">
                                                            <!--标识时间格式化-->
                                                            <el-date-picker v-model="item.defaultvalue" type="datetime" placeholder="选择日期" value-format="yyyy-MM-dd HH:mm:ss" style="width:130px">
                                                            </el-date-picker>
                                                        </div>
                                                        <div v-else>
                                                            <el-date-picker v-model="item.defaultvalue" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" style="width:130px">
                                                            </el-date-picker>
                                                        </div>
                                                    </div>
                                                    <!--1 复选框-->
                                                    <div v-else-if="item.valuetype=='1'">
                                                        <el-checkbox true-label="1" false-label="0" v-model="item.defaultvalue"></el-checkbox>
                                                    </div>
                                                    <!--2 输入框-->
                                                    <div v-else-if="item.valuetype=='2'">
                                                        <el-input v-model="item.defaultvalue"></el-input>
                                                    </div>
                                                    <!--3 单选框-->
                                                    <div v-else-if="item.valuetype=='3'">
                                                        <!--包含两种，竖线分割以及sql语句-->
                                                        <el-select v-model="item.defaultvalue">
                                                            <el-option v-for="(oneitem, index) in item.valuelist.split('|')" :key="index" :label="oneitem.split(' ')[1]" :value="oneitem.split(' ')[0]"></el-option>
                                                        </el-select>
                                                        <!-- <rm-select v-model="item.defaultvalue" filterable style="width:100%" :sql="item.valuelist" :keyid="item.colcode+'$'+item.statreportid" @change="SqlSingleChange">
                                                        </rm-select> -->
                                                    </div>
                                                    <!--12 SQL单选框-->
                                                    <div v-else-if="item.valuetype=='12'">
                                                        <!--包含两种，竖线分割以及sql语句-->
                                                        <rm-select v-model="item.defaultvalue" filterable style="width:100%" :sql="item.valuelist" :keyid="item.colcode+'$'+item.statreportid" @change="SqlSingleChange">
                                                        </rm-select>
                                                    </div>
                                                    <!--4 多选框-->
                                                    <div v-else-if="item.valuetype=='4' || item.valuetype=='11'">
                                                        <!--包含两种，竖线分割以及sql语句-->
                                                        <el-input v-model="item.defaultvaluename" ref="refSql" :key="item.colcode" placeholder="多选双击开窗" readonly @dblclick.native="DialogSql(item)">
                                                            <el-button slot="append" @click.native="DialogSql(item)">选择</el-button>
                                                        </el-input>
                                                    </div>
                                                    <!--7 报告单元单选框-->
                                                    <div v-else-if="item.valuetype=='7'">
                                                        <rm-ddl-rptunit prgno="LIS490" v-model="item.defaultvalue"></rm-ddl-rptunit>
                                                    </div>
                                                    <!--8 报告单元多选框-->
                                                    <div v-else-if="item.valuetype=='8'">
                                                        <!--包含两种，竖线分割以及sql语句-->
                                                        <el-input v-model="item.defaultvaluename" ref="refSql" :key="item.colcode" placeholder="多选双击开窗" readonly @dblclick.native="DialogSql(item)">
                                                            <el-button slot="append" @click.native="DialogSql(item)">选择</el-button>
                                                        </el-input>
                                                    </div>
                                                    <div v-else-if="item.valuetype=='9'">
                                                        <el-date-picker v-model="item.defaultvalue[0]" :type="item.dateformat=='1'?'datetime':'date'" placeholder="选择日期" :value-format="item.dateformat=='1'?'yyyy-MM-dd HH:mm:ss':'yyyy-MM-dd'" :style="{ width:item.dateformat=='1'?'160px':'130px'}"></el-date-picker>-
                                                        <el-date-picker v-model="item.defaultvalue[1]" :type="item.dateformat=='1'?'datetime':'date'" placeholder="选择日期" :value-format="item.dateformat=='1'?'yyyy-MM-dd HH:mm:ss':'yyyy-MM-dd'" :style="{ width:item.dateformat=='1'?'160px':'130px'}">
                                                        </el-date-picker>
                                                    </div>
                                                    <div v-else-if="item.valuetype=='10'">
                                                        <el-input v-model="item.defaultvalue"></el-input>
                                                    </div>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                            </table>
                        </div>
                        <!--按钮放这里-->
                        <div style="float:right;height:30px;margin-right:5px;vertical-align: center">
                            <el-button @click.native="dialogMoreVisble = true" icon="el-icon-menu" style="padding-right: 5px">更多条件</el-button>
                            <el-button @click.native="btnQuery" icon="el-icon-search" type="primary" style="padding-right: 5px">查询</el-button>
                            <el-dropdown style="padding-left: 5px;padding-right: 5px">
                                <el-button icon="el-icon-document">导出</el-button>
                                <el-dropdown-menu slot="dropdown">
                                    <el-dropdown-item @click.native="btnExport('xlsx')">Excel</el-dropdown-item>
                                    <el-dropdown-item @click.native="btnExport('pdf')">PDF</el-dropdown-item>
                                    <el-dropdown-item @click.native="btnExport('xlsx-2')">Excel-2</el-dropdown-item>
                                    <el-dropdown-item @click.native="btnExport('pdf-2')">PDF-2</el-dropdown-item>
                                </el-dropdown-menu>
                            </el-dropdown>
                            <el-button @click.native="btnExport('print')" icon="el-icon-printer">打印</el-button>
                        </div>
                    </div>
                </div>
            </template>
            <rm-layout-left splitcolor="white" movingcolor="#0000ff" :splitwidth=5 :fixsize="400" v-show="ShowByMenu">
                <template v-slot:fix>
                    <div style="border:1px solid #CCC;height:100%">
                        <el-tree class="filter-tree" :data="data" :props="defaultProps" default-expand-all node-key="statreportid" @node-click="tree_click_event" ref="tree" highlight-current>
                        </el-tree>
                    </div>
                </template>
                <div style="height:100%;width:100%;text-align:center;border:1px solid #CCC;overflow:auto" v-loading="rightloading" element-loading-text="数据加载中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)">
                    <!-- <div v-html="htmlstr"></div> -->
                    <embed :src="htmlstr" type="application/pdf" width="100%" height="99%" :key="htmlstrkey">
                    <!-- <pdf v-for="i in pdfPages" :key="i" :src="url" :page="i"></pdf> -->
                    <!-- <pdf :src="url" :page="1"></pdf> -->
                </div>
            </rm-layout-left>
            <div style="height:100%;width:100%;text-align:center;border:1px solid #CCC;overflow:auto" v-loading="rightloading" element-loading-text="数据加载中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)" v-show="!ShowByMenu">
                <embed :src="htmlstr" type="application/pdf" width="100%" height="99%" :key="htmlstrkey">
                <!-- <pdf v-for="i in pdfPages" :key="i" :src="url" :page="i"></pdf> -->
                <!-- <pdf :src="url" :page="1"></pdf> -->
                <!-- <pdf :src="url" ref="ref" class="pdf" :page="pdfPages"></pdf> -->

                <!-- <el-image style="height:100%;width:100%;text-align:center;border:1px solid #CCC;overflow:auto" v-model="htmlstr"></el-image> -->
                <!-- <div style="height:100%;width:100%;text-align:center;border:1px solid #CCC;overflow:auto" v-html="htmlstr"></div> -->
            </div>
        </rm-layout-top>
        <!--多选弹窗--->
        <el-dialog width="900px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :title="multichktitle" :visible.sync="dialogMultipleVisible" :destroy-on-close="true" v-if="dialogMultipleVisible">
            <rm-SqlMultiple :leftOption="LeftListOptions" :rightOption="RightListOptions" :name="fieldname" @change="closedialog"></rm-SqlMultiple>
        </el-dialog>

        <!--更多条件弹窗--->
        <el-dialog width="900px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="更多条件" :visible.sync="dialogMoreVisble" :destroy-on-close="true">
            <table style="width: 100%">
                <tr v-for="(item,index) in MoreCondData" :key="index">
                    <td style="width:60px" align="right"> {{item.colname}}</td>
                    <td :style="{ width: item.valuetype == '9' ?'270px': '135px' }">
                        <div v-if="item.valuetype=='0'">
                            <!--标识时间选择框--->
                            <div v-if="item.dateformat=='1'">
                                <!--标识时间格式化-->
                                <el-date-picker v-model="item.defaultvalue" type="datetime" placeholder="选择日期" value-format="yyyy-MM-dd HH:mm:ss" style="width:130px">
                                </el-date-picker>
                            </div>
                            <div v-else>
                                <el-date-picker v-model="item.defaultvalue" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" style="width:130px">
                                </el-date-picker>
                            </div>
                        </div>
                        <!--1 复选框-->
                        <div v-else-if="item.valuetype=='1'">
                            <el-checkbox true-label="1" false-label="0" v-model="item.defaultvalue"></el-checkbox>
                        </div>
                        <!--2 输入框-->
                        <div v-else-if="item.valuetype=='2'">
                            <el-input v-model="item.defaultvalue"></el-input>
                        </div>
                        <!--3 单选框-->
                        <div v-else-if="item.valuetype=='3'">
                            <!--包含两种，竖线分割以及sql语句-->
                            <el-select v-model="item.defaultvalue">
                                <el-option v-for="(oneitem, index) in item.valuelist.split('|')" :key="index" :label="oneitem.split(' ')[1]" :value="oneitem.split(' ')[0]"></el-option>
                            </el-select>
                            <!-- <rm-select v-model="item.defaultvalue" filterable style="width:100%" :sql="item.valuelist" :keyid="item.colcode+'$'+item.statreportid" @change="SqlSingleChange">
                            </rm-select> -->
                        </div>
                        <!--12 SQL单选框-->
                        <div v-else-if="item.valuetype=='12'">
                            <!--包含两种，竖线分割以及sql语句-->
                            <rm-select v-model="item.defaultvalue" filterable style="width:100%" :sql="item.valuelist" :keyid="item.colcode+'$'+item.statreportid" @change="SqlSingleChange">
                            </rm-select>
                        </div>
                        <!--4 多选框-->
                        <div v-else-if="item.valuetype=='4' || item.valuetype=='11'">
                            <!--包含两种，竖线分割以及sql语句-->
                            <el-input v-model="item.defaultvaluename" ref="refSql" :key="item.colcode" placeholder="多选双击开窗" readonly @dblclick.native="DialogSql(item)">
                                <el-button slot="append" @click.native="DialogSql(item)">选择</el-button>
                            </el-input>
                        </div>
                        <!--7 报告单元单选框-->
                        <div v-else-if="item.valuetype=='7'">
                            <rm-ddl-rptunit prgno="LIS490" v-model="item.defaultvalue"></rm-ddl-rptunit>
                        </div>
                        <!--8 报告单元多选框-->
                        <div v-else-if="item.valuetype=='8'">
                            <!--包含两种，竖线分割以及sql语句-->
                            <el-input v-model="item.defaultvaluename" ref="refSql" :key="item.colcode" placeholder="多选双击开窗" readonly @dblclick.native="DialogSql(item)">
                                <el-button slot="append" @click.native="DialogSql(item)">选择</el-button>
                            </el-input>
                        </div>
                        <div v-else-if="item.valuetype=='9'">
                            <el-date-picker v-model="item.defaultvalue[0]" :type="item.dateformat=='1'?'daretime':'date'" placeholder="选择日期" :value-format="item.dateformat=='1'?'yyyy-MM-dd HH:mm:ss':'yyyy-MM-dd'" style="width:130px"></el-date-picker>-
                            <el-date-picker v-model="item.defaultvalue[1]" :type="item.dateformat=='1'?'daretime':'date'" placeholder="选择日期" :value-format="item.dateformat=='1'?'yyyy-MM-dd HH:mm:ss':'yyyy-MM-dd'" style="width:130px">
                            </el-date-picker>
                        </div>
                        <div v-else-if="item.valuetype=='10'">
                            <el-input v-model="item.defaultvalue"></el-input>
                        </div>

                    </td>
                </tr>
            </table>
            <div style="float:right;height:30px;margin-right:5px">
                <el-button @click="dialogMoreVisble = false">关 闭</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils";
// import pdf from "vue-pdf";
export default {
    // components: {
    //     pdf
    // },
    name: "LIS490",
    data() {
        return {
            searchObj: {
                startdt: this.$pub.InitDate(),
                enddt: this.$pub.InitDate()
            },
            CondDatas: [],
            OriCondDatas: [],
            MoreCondData: [],
            keyConfig: {
                isDel: true,
                isTab: true,
                isEdit: false
            },
            keyLocalConfig: {
                isArrow: true
            },
            selectConfig: { tigger: "row", checkAll: true, reserve: true },
            selectRow: [],
            reqgroupOption: [],
            userno: this.$tool.getSession(this.$tool.loginuserno),
            data: [],
            defaultProps: {
                children: "children",
                label: "label"
            },
            dialogMultipleVisible: false,
            LeftListOptions: [],
            RightListOptions: [],
            fieldname: "",
            multichktitle: "",
            diagPreCond: false,
            SqlTitle: "",
            rightloading: false,
            autoheight: 0,
            pagekey: 0,
            ShowByMenu: true,
            currentmenu: "",
            //pdf
            // pdfPages: 1,
            // url: "",
            // vuePdf: "",
            //更多条件弹窗
            dialogMoreVisble: false,
            rptunitOption: [],
            ChangeRow: {},
            htmlstr: "",
            htmlstrkey: 0
        };
    },
    created() {
        this.InitTree(); //初始化树
        // this.vuePdf = require("vue-pdf");
        if (this.$route.query.id) {
            this.GetTitle(this.$route.query.id);
        }
    },
    mounted() {},
    updated() {},
    computed: {},
    methods: {
        GetTitle(id) {
            this.$tool
                .request({
                    url: "LIS/LIS4/LIS490",
                    method: "post",
                    data: {
                        action: "getTitle",
                        id: id
                    }
                })
                .then(res => {
                    if (res.errcode == "1") {
                        if (res.dt.length > 0) {
                            this.$tool.setTitle(res.dt[0].prgname);
                        } else {
                            this.$tool.setTitle("自定义报表" + id);
                        }
                    } else {
                        this.$tool.setTitle("自定义报表" + id);
                    }
                });
        },
        //树初始化
        InitTree() {
            this.autoheight = 0;
            this.pagekey++;
            this.$tool
                .request({
                    url: "LIS/LIS4/LIS490",
                    method: "post",
                    data: {
                        action: "InitTree",
                        ...this.searchObj
                    }
                })
                .then(res => {
                    let menu = this.$tool.getSession("currentmenu").substring(0, 6);
                    let selectmenu = res.data.find(item => item.prgcode == menu);
                    this.rptunitOption = res.rptunitOption;
                    if (menu != "LIS490" && selectmenu) {
                        this.searchObj.prgcode = menu; //这个值是为了保持树的key唯一性
                        this.searchObj.statreportid = selectmenu.statreportid;
                        this.searchObj.type = "InitPage";
                        this.ShowByMenu = false;
                        this.queryRight(1);
                        return;
                    } else {
                        res.kindlist.forEach((item, index) => {
                            let data = res.data.filter(m => m.reportkind == item.reportkind);
                            let kdata = { id: "id_" + index, label: item.reportkind };
                            if (data.length > 0) {
                                let tmp = [];
                                data.forEach(ele => {
                                    tmp.push({ id: ele.prgcode + "$" + ele.statreportid, label: ele.reportname });
                                });
                                kdata.children = tmp;
                            }
                            this.data.push(kdata);
                        });
                    }
                })
                .catch(e => {
                    this.$alert(e, "出错");
                });
        },
        //预览
        previewData(StatColName, StatData, type) {
            if (StatData && StatData.length == 0) {
                // this.url = "";
                //this.prePDFDialogShow(url);
                this.$alert("当前条件无数据，请更换查询条件后再试!", "提示");
                return;
            }
            this.rightloading = true;
            // let str = "";
            // if (StatData == "") {
            //     str = StatColName;
            // } else {
            //     str = JSON.stringify(StatColName);
            //     str += "\r";
            //     str += JSON.stringify(StatData);
            // }
            // let sql = btoa(encodeURIComponent(str));
            // this.$tool
            //     .request({
            //         url: "ucent/print",
            //         method: "post",
            //         data: {
            //             action: this.searchObj.type == "chart" ? "customprintview" : "PreviewCustomJson",
            //             styleid: this.searchObj.statreportid,
            //             sql: this.searchObj.type == "chart" ? sql : str,
            //             tablename: "chartreport"
            //         }
            //     })
            //     .then(res => {
            //         if (res == "获取报告预览数据出错！") res = "未查询到数据";
            //         this.htmlstr = res;
            //         this.rightloading = false;
            //     })
            //     .catch(e => {
            //         this.rightloading = false;
            //         this.$alert(e, "出错");
            //     });

            this.$tool
                .request({
                    url: "ucent/print",
                    method: "post",
                    data: {
                        action: "previewpdfbysql",
                        styleid: this.searchObj.statreportid,
                        sql: this.$tool.Encrypt(type),
                        tablename: "report"
                    }
                })
                .then(res => {
                    if (res.flag == "0") {
                        this.$alert(res.msg, "提示");
                    } else {
                        //var url = res.pdfurl;
                        this.htmlstr = res.pdfurl + "#toolbar=0";
                        this.htmlstrkey++;
                        //this.prePDFDialogShow(url);
                        //this.$bus.$emit("prePDFDialog", res.pdfurl);
                    }
                    this.rightloading = false;
                })
                .catch(e => {
                    this.$alert("预览报告出错！", "错误", {
                        confirmButtonText: "确定"
                    });
                    this.rightloading = false;
                });
        },
        //pdf preview
        // prePDFDialogShow(url) {
        //     this.url = pdf.createLoadingTask(url);
        //     this.url.promise.then(pdf => {
        //         this.pdfPages = pdf.numPages;
        //         //this.url = url;
        //     });
        // },

        //子节点被点击
        tree_click_event(data, node, key) {
            let keyid = node.data.id;
            if (keyid.indexOf("$") > -1) {
                //横向查
                //表示子节点被点击
                this.searchObj.prgcode = keyid.split("$")[0]; //这个值是为了保持树的key唯一性
                this.searchObj.statreportid = keyid.split("$")[1];
                this.searchObj.type = "InitPage";
                this.queryRight(1);
            } else {
                //表示父节点被点击
                //console.log("parentnode");
            }
        },
        //更多条件确定
        saveRecord() {
            this.OriCondDatas.forEach(item => {
                let data = this.preCondData.find(m => m.statreportid == item.statreportid && m.colcode == item.colcode);
                if (!!data) {
                    item.condoperator = data.condoperator;
                    item.defaultvalue = data.defaultvalue;
                }
            });
            this.diagPreCond = false;
        },
        btnQuery() {
            function flatten(arr) {
                var arr;
                while (arr.some(v => Array.isArray(v))) {
                    arr = [].concat(...arr);
                }
                return arr;
            }
            this.OriCondDatas = flatten(this.CondDatas);
            var moreCondDatas = flatten(this.MoreCondData);
            //更多条件中的搜索条件附加
            for (let index = 0; index < moreCondDatas.length; index++) {
                const element = moreCondDatas[index];
                this.OriCondDatas.push(element);
            }
            this.searchObj.type = "queryRight";
            this.queryRight(2);
        }, //预览数据及查询条件初始化
        btnExport(type) {
            var urecdata = XEUtils.clone(this.OriCondDatas, true);
            for (let i = 0; i < urecdata.length; i++) {
                if (urecdata[i].valuetype == "9") {
                    urecdata[i].defaultvalue = urecdata[i].defaultvalue[0] + "|" + urecdata[i].defaultvalue[1];
                }
            }
            if(type == "print"){
                this.searchObj.type = "queryRight";
                this.$tool
                    .request({
                        url: "LIS/LIS4/LIS490",
                        method: "post",
                        timeout: 600000,
                        data: {
                            action: "queryRight",
                            urec: urecdata,
                            ...this.searchObj
                        }
                    })
                    .then(res => {
                        //当前
                        if (res.errmsg != "") {
                            this.$alert(res.errmsg, "提示");
                        } else {
                            //这里要取报表的名称
                            let reportname = res.reportname;
                            if (!reportname) reportname = "导出";
                            let StatColName = res.columns;
                            let StatData = res.datas;
                            let str = "";
                            if (StatData == "") {
                                str = StatColName;
                            } else {
                                str = JSON.stringify(StatColName);
                                str += "\r";
                                str += JSON.stringify(StatData);
                            }
                            let sql = btoa(encodeURIComponent(str));
                            //jsObj.SetCustomJsonPrintConfig(this.searchObj.statreportid, sql, this.userno, reportname);
                            console.log(this.userno);
                            jsObj.PrintCustomJsonReport(this.searchObj.statreportid+"", sql, this.userno+"", "report", "");
                        }
                    })
                    .catch(e => {
                        this.$alert(e, "出错");
                    });
            }
            else if(type == "xlsx-2" || type == "pdf-2"){
            this.searchObj.type = "queryRight";
            this.$tool
                .request({
                    url: "LIS/LIS4/LIS490",
                    method: "post",
                    timeout: 600000,
                    data: {
                        action: "queryRight",
                        urec: urecdata,
                        ...this.searchObj
                    }
                })
                .then(res => {
                    //当前

                    if (res.errmsg != "") {
                        this.$alert(res.errmsg, "提示");
                    } else {
                        let StatColName = res.columns;
                        let StatData = res.datas;
                        let str = "";
                        if (StatData == "") {
                            str = StatColName;
                        } else {
                            str = JSON.stringify(StatColName);
                            str += "\r";
                            str += JSON.stringify(StatData);
                        }
                        //这里要取报表的名称
                        let reportname = res.reportname;
                        if (!reportname) reportname = "导出";
                        if (type == "xlsx-2") {
                            var p = { prgno: "ExportExcelCustomJson", styleid: this.searchObj.statreportid, sql: str, tablename: "report", reportname: reportname };
                            this.$pub.commexport(this, p, reportname + ".xlsx");
                        } else if (type == "pdf-2") {
                            let p = { prgno: "ExportPdfCustomJson", styleid: this.searchObj.statreportid, sql: str, tablename: "report", reportname: reportname };
                            this.$pub.commexport(this, p, reportname + ".pdf");
                        } 
                    }
                })
                .catch(e => {
                    this.$alert(e, "出错");
                });
            }
             else {
                this.$tool
                    .request({
                        url: "LIS/LIS4/LIS490",
                        method: "post",
                        data: {
                            action: "getreportsql",
                            urec: urecdata,
                            statreportid: this.searchObj.statreportid,
                        }
                    })
                    .then(res => {
                        if(res.flag == "1"){
                            var systemtime = XEUtils.toDateString(new Date(), "yyyy-MM-dd HH:mm:ss");
                            let reportname = res.reportname;
                            if (!reportname) reportname = "导出";
                            if (type == "xlsx") {
                                var p = { prgno: "ExportExcelCustomJsonBySql", styleid: this.searchObj.statreportid, sql: this.$tool.Encrypt(res.statsql), tablename: "report", reportname: reportname };
                                //this.$pub.commexport(this, p, reportname + systemtime + ".xlsx");
                                this.$pub.bigdataexport(this, p, reportname + systemtime + ".xlsx", "正在导出Excel，请稍候。。。");
                            } else if (type == "pdf") {
                                let p = { prgno: "ExportPdfCustomJsonBySql", styleid: this.searchObj.statreportid, sql: this.$tool.Encrypt(res.statsql), tablename: "report", reportname: reportname };
                                //this.$pub.commexport(this, p, reportname + systemtime + ".pdf");
                                this.$pub.bigdataexport(this, p, reportname + systemtime + ".pdf", "正在导出PDF，请稍候。。。");
                            }
                        } else {
                            this.$alert("未检索到统计报告对应数据，请检查！", "出错");
                        }
                    })
                    .catch(e => {
                        this.$alert(e, "出错");
                    });
            }
        },
        queryRight(type) {
            var urecdata = XEUtils.clone(this.OriCondDatas, true);
            for (let i = 0; i < urecdata.length; i++) {
                if (urecdata[i].valuetype == "9") {
                    urecdata[i].defaultvalue = urecdata[i].defaultvalue[0] + "|" + urecdata[i].defaultvalue[1];
                }
            }
            let currentnode = this.$refs.tree.getCurrentNode();
            this.$tool
                .request({
                    url: "LIS/LIS4/LIS490",
                    method: "post",
                    timeout: 600000,
                    data: {
                        action: "queryRight",
                        urec: urecdata,
                        ...this.searchObj
                    }
                })
                .then(res => {
                    //初始化查询(获取当前时间下默认条件的预览数据与更多条件初始化)
                    if (this.searchObj.type == "InitPage") {
                        if (res.errmsg != "") {
                            this.$alert(res.errmsg, "提示");
                        } else {
                            let data = res.preCondData;
                            this.OriCondDatas = XEUtils.clone(data, true);
                            //计算行数
                            let len = data.length;
                            let rows = Math.ceil(len / 6);
                            //计算高度
                            this.autoheight = 33 * (rows + 1);
                            this.$refs.topdiv.style.height = this.autoheight + "px";
                            this.$refs.layoutdiv.$el.childNodes[0].style.height = this.autoheight + "px";
                            this.$refs.layoutdiv.$el.childNodes[3].style.top = this.autoheight + 5 + "px";
                            //this.pagekey++;
                            //分组切片
                            var condData = data.filter(item => item.showmode == "A" || item.showmode == "1");
                            this.MoreCondData = data.filter(item => item.showmode == "A" || item.showmode == "2");
                            this.CondDatas = XEUtils.chunk(condData, 6);
                            for (let i = 0; i < this.CondDatas.length; i++) {
                                for (let j = 0; j < this.CondDatas[i].length; j++) {
                                    if (this.CondDatas[i][j].valuetype == "9") {
                                        var newarr = this.CondDatas[i][j].defaultvalue.split("|");
                                        this.CondDatas[i][j].defaultvalue = newarr;
                                    }
                                }
                            }
                            //var conddt = XEUtils.chunk(data, 6);
                            // for (let i = 0; i < conddt.length; i++) {
                            //     var hasdata = [];
                            //     var condchilddata = [];
                            //     for (let j = 0; j < conddt[i].length; j++) {
                            //         var searchdt = hasdata.find(item => item.colcode.substring(0, 3) == conddt[i][j].colcode.substring(0, 3));
                            //         if (searchdt) {
                            //             condchilddata[searchdt.index].push(conddt[i][j]);
                            //         } else {
                            //             hasdata.push({ colcode: conddt[i][j].colcode, index: j });
                            //             condchilddata.push([conddt[i][j]]);
                            //         }
                            //     }
                            //     this.CondDatas.push(condchilddata);
                            // }

                            // 点击树节点和初始化时不进行预览查询
                            //this.previewData(res.columns, res.datas, res.statsql);
                            if (type == 2) {
                                this.previewData(res.columns, res.datas, res.statsql);
                            } else {
                                // this.url = "";
                                // this.pdfPages = 1;
                            }
                        }
                    } else {
                        //当前
                        if (res.errmsg != "") {
                            this.$alert(res.errmsg, "提示");
                        } else {
                            this.previewData(res.columns, res.datas, res.statsql);
                        }
                    }
                })
                .catch(e => {
                    this.$alert(e, "出错");
                    //this.$refs.tree.setCurrentKey(currentmode);
                });
        },
        //多选弹窗关闭
        closedialog(value, code, valuename) {
            if (value != "close") {
                // if(value.indexOf(",") != -1) {
                //     value=value.replace(/,/g,'\',\'');
                // }
                // value='\''+value+'\'';
                this.ChangeRow.defaultvalue = value;
                this.ChangeRow.defaultvaluename = valuename;
            }
            this.dialogMultipleVisible = false;
        },
        //sql多选弹窗
        DialogSql(item) {
            console.log(item);
            this.SqlTitle = item.colname;
            this.fieldname = item.colcode;
            this.multichktitle = item.colname;
            var rowlist = [];
            if (item.defaultvalue) rowlist = item.defaultvalue.split(",");
            this.ChangeRow = item;
            if (item.valuetype == "4") {
                var alloption = [];
                var alloptionlist = item.valuelist.split("|");
                for (let i = 0; i < alloptionlist.length; i++) {
                    alloption.push({ data: alloptionlist[i].split(" ")[0], display: alloptionlist[i].split(" ")[1], inputcode: "" });
                }
                if (rowlist.length > 0) {
                    this.LeftListOptions = alloption.filter(item => rowlist.indexOf(item.data) == -1);
                    this.RightListOptions = alloption.filter(item => rowlist.indexOf(item.data) > -1);
                } else {
                    this.LeftListOptions = alloption;
                    this.RightListOptions = [];
                }
            } else if (item.valuetype == "11") {
                var alloption = [];
                //请求后台
                this.$tool
                    .request({
                        url: "LIS/LIS4/LIS490",
                        method: "post",
                        data: {
                            action: "getoptionlist",
                            sqlstr: item.valuelist,
                        },
                    })
                    .then((res) => {
                        if (res.flag == "1") {
                            var alloptionlist = res.data;
                            console.log(alloptionlist);
                            for (let i = 0; i < alloptionlist.length; i++) {
                                alloption.push({ data: alloptionlist[i].data, display: alloptionlist[i].title, inputcode: alloptionlist[i].inputcode });
                            }
                            if (rowlist.length > 0) {
                                this.LeftListOptions = alloption.filter((item) => rowlist.indexOf(item.data) == -1);
                                this.RightListOptions = alloption.filter((item) => rowlist.indexOf(item.data) > -1);
                            } else {
                                this.LeftListOptions = alloption;
                                this.RightListOptions = [];
                            }
                        } else {
                            this.$message({
                                message: res.msg,
                                type: "warning",
                            });
                        }
                    });
            }
            else if (item.valuetype == "8") {
                this.LeftListOptions = this.rptunitOption.filter(item => rowlist.indexOf(item.data + "") == -1);
                this.RightListOptions = this.rptunitOption.filter(item => rowlist.indexOf(item.data + "") > -1);
            }
            this.dialogMultipleVisible = true;
        },
        //单选赋值
        SqlSingleChange(value, idcode) {
            let code = idcode.split("$")[0];
            let id = idcode.split("$")[1];

            var tempArr = this.CondDatas[0];
            var moretempArr = this.MoreCondData[0];
            //页面上的搜索条件赋值
            if(tempArr != undefined && !!tempArr.length){
                for (let index = 0; index < tempArr.length; index++) {
                    var element = tempArr[index];
                    if(element.colcode == code && element.statreportid == id){
                        tempArr[index].defaultvalue = value;
                    }
                }
            }
            else {
                if(tempArr != undefined && tempArr.colcode == code && tempArr.statreportid == id){
                    tempArr.defaultvalue = value;
                }
            }
            //更多条件中的搜索条件赋值
            if(moretempArr != undefined && !!moretempArr.length){
                for (let index = 0; index < moretempArr.length; index++) {
                    var element = moretempArr[index];
                    if(element.colcode == code && element.statreportid == id){
                        moretempArr[index].defaultvalue = value;
                    }
                }
            }
            else{
                if(moretempArr != undefined && moretempArr.colcode == code && moretempArr.statreportid == id){
                    moretempArr.defaultvalue = value;
                }
            }
        } //赋值函数
    }
};
</script>

<style scoped>
.pagetop {
    width: 100%;
    left: 0;
    right: 0;
    display: -webkit-box;
    -webkit-box-pack: center;
    -webkit-box-align: center;
    border: solid 1px #ccc;
    position: absolute;
    z-index: 99;
    height: 40px;
    overflow-x: auto;
    overflow-x: overlay;
}

.pagecenter {
    position: absolute;
    top: 45px;
    width: 100%;
    left: 0px;
    bottom: 0px;
    overflow: auto;
}

.middle-center {
    position: absolute;
    height: 100%;
    left: 0px;
    right: 0px;
    overflow: auto;
}

::v-deep .myclass .vxe-table .vxe-footer--row.row-blue {
    background-color: #187;
    color: #fff;
}

::v-deep .el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content {
    background-color: #b6e8ff;
    font-weight: 700;
}
::v-deep .el-input--suffix .el-input__inner {
    padding-right: 10px;
}
.operation-list {
    float: right;
    margin-right: 5px;
    margin-bottom: 5px;
}
.table1style tr td {
    padding: 2px 3px 2px 3px;
}
</style>